package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Person p = new Person();
//        p.heiheihei();
        //编译不通过，因为类的外部不可以方法类的私有成员
        Class cls=Class.forName("reflect.Person");
        Object obj =cls.newInstance();


        Method method=cls.getDeclaredMethod("heiheihei");
        method.setAccessible(true);//强行打开访问权限
        method.invoke(obj);
        method.setAccessible(false);//调用后尽量还原权限

    }
}
